//
//  MAPYHomeConnectCell.swift
//  Mars Proxy
//
//  Created by PowerfullClean on 2023/10/16.
//

import UIKit
import Lottie

class MAPYHomeConnectCell: UICollectionViewCell {
    override init(frame: CGRect) {
        super.init(frame: frame)
        contentView.addSubview(mapy_titleLabel)
        contentView.addSubview(mapy_bottomView)
        contentView.addSubview(mapy_connectButton)
        contentView.addSubview(mapy_downloadLabel)
        contentView.addSubview(mapy_downloadValueLabel)
        contentView.addSubview(mapy_downUnitLabel)
        contentView.addSubview(mapy_uploadLabel)
        contentView.addSubview(mapy_uploadValueLabel)
        contentView.addSubview(mapy_upUnitLabel)
        contentView.addSubview(mapy_changeView)
        contentView.addSubview(mapy_selectView)
        contentView.addSubview(mapy_ipView)
        contentView.addSubview(mapy_speedView)
        contentView.addSubview(mapy_connectAnimeView)
        contentView.addSubview(mapy_disConnectAnimeView)
        contentView.addSubview(mapy_iPValueLabel)
        contentView.addSubview(mapy_timeView)
        mapy_ipView.snp.makeConstraints { make in
            make.size.equalTo(102)
            make.right.equalToSuperview().offset(-20)
            make.centerY.equalTo(mapy_titleLabel.snp.centerY)
        }
        mapy_speedView.snp.makeConstraints { make in
            make.size.equalTo(102)
            make.right.equalTo(mapy_ipView.snp.left).offset(2)
            make.top.equalTo(mapy_titleLabel.snp.bottom).offset(5)
        }
        mapy_titleLabel.snp.makeConstraints { make in
            make.top.equalToSuperview().offset(44)
            make.left.equalToSuperview().offset(20)
            make.height.equalTo(35)
        }
        mapy_bottomView.snp.makeConstraints { make in
            make.height.equalTo(510)
            make.left.equalToSuperview()
            make.bottom.equalToSuperview().offset(20)
            make.right.equalToSuperview()
        }
        mapy_connectButton.snp.makeConstraints { make in
            make.size.equalTo(CGSize(width: 190, height: 200))
            make.right.equalToSuperview()
            make.top.equalTo(mapy_bottomView.snp.top)
        }
        mapy_downloadLabel.snp.makeConstraints { make in
            make.top.equalTo(mapy_bottomView.snp.top).offset(20)
            make.left.equalToSuperview().offset(28)
        }
        mapy_downloadValueLabel.snp.makeConstraints { make in
            make.top.equalTo(mapy_downloadLabel.snp.bottom)
            make.centerX.equalTo(mapy_downloadLabel.snp.centerX)
            make.height.equalTo(28)
        }
        mapy_downUnitLabel.snp.makeConstraints { make in
            make.top.equalTo(mapy_downloadValueLabel.snp.bottom)
            make.centerX.equalTo(mapy_downloadLabel.snp.centerX)
        }
        mapy_uploadLabel.snp.makeConstraints { make in
            make.top.equalTo(mapy_downUnitLabel.snp.bottom).offset(16)
            make.centerX.equalTo(mapy_downloadLabel.snp.centerX)
        }
        mapy_uploadValueLabel.snp.makeConstraints { make in
            make.top.equalTo(mapy_uploadLabel.snp.bottom)
            make.centerX.equalTo(mapy_uploadLabel.snp.centerX)
            make.height.equalTo(28)
        }
        mapy_upUnitLabel.snp.makeConstraints { make in
            make.top.equalTo(mapy_uploadValueLabel.snp.bottom)
            make.centerX.equalTo(mapy_uploadLabel.snp.centerX)
        }
        mapy_changeView.snp.makeConstraints { make in
            make.left.equalToSuperview().offset(15)
            make.right.equalToSuperview().offset(-15)
            make.height.equalTo(72)
            make.top.equalTo(mapy_connectButton.snp.bottom).offset(8)
        }
        mapy_selectView.snp.makeConstraints { make in
            make.left.equalToSuperview().offset(15)
            make.right.equalToSuperview().offset(-15)
            make.height.equalTo(68)
            make.top.equalTo(mapy_changeView.snp.bottom).offset(6)
        }
        mapy_connectAnimeView.snp.makeConstraints { make in
            make.edges.equalTo(mapy_connectButton)
        }
        mapy_disConnectAnimeView.snp.makeConstraints { make in
            make.edges.equalTo(mapy_connectButton)
        }
        
        mapy_iPValueLabel.snp.makeConstraints { make in
            make.left.equalTo(mapy_titleLabel.snp.left)
            make.top.equalTo(mapy_titleLabel.snp.bottom).offset(10)
        }
        mapy_timeView.snp.makeConstraints { make in
            make.top.left.equalTo(mapy_bottomView)
            make.right.equalTo(mapy_connectButton.snp.left).offset(-5)
            make.bottom.equalTo(mapy_uploadValueLabel.snp.bottom)
        }
        contentView.layer.masksToBounds = true
        
        MAPYManager.mapy_manager.mapy_vpnChangeBlock = {[weak self] mapy_state in
            //            print(mapy_state.mapy_title)
            
            if mapy_state == .mapy_connected {
                self?.mapy_connectButton.isSelected = true
                self?.mapy_connectAnimeView.isHidden = true
                self?.mapy_connectAnimeView.stop()
                self?.mapy_disConnectAnimeView.isHidden = true
                self?.mapy_disConnectAnimeView.stop()
                //                self?.mapy_ipView.isHidden = false
                //                self?.mapy_speedView.isHidden = false
                self?.mapy_titleLabel.text = "CONNECTED"
                self?.mapy_viewGetVController?.navigationController?.pushViewController(MAPYConnectResultViewController(mapy_connected: true), animated: true)
                
            }
            if mapy_state == .mapy_connecting {
                
                self?.mapy_titleLabel.text = "CONNECTING"
                if !(self?.mapy_connectAnimeView.isAnimationPlaying ?? false) {
                    self?.mapy_connectAnimeView.isHidden = false
                    self?.mapy_connectAnimeView.play()
                }
            }
            if mapy_state == .mapy_disconnecting {
                self?.mapy_titleLabel.text = "DISCONNECTING"
                if !(self?.mapy_disConnectAnimeView.isAnimationPlaying ?? false) {
                    self?.mapy_disConnectAnimeView.isHidden = false
                    self?.mapy_disConnectAnimeView.play()
                }
            }
            if mapy_state == .mapy_disconnected {
                self?.mapy_connectButton.isSelected = false
                self?.mapy_disConnectAnimeView.isHidden = true
                self?.mapy_disConnectAnimeView.stop()
                self?.mapy_connectAnimeView.isHidden = true
                self?.mapy_connectAnimeView.stop()
                //                self?.mapy_ipView.isHidden = true
                //                self?.mapy_speedView.isHidden = true
                self?.mapy_titleLabel.text = "NO CONNECT"
                self?.mapy_viewGetVController?.navigationController?.pushViewController(MAPYConnectResultViewController(mapy_connected: false), animated: true)
                
            }
            if mapy_state == .mapy_invalid {
                self?.mapy_connectButton.isSelected = false
                self?.mapy_disConnectAnimeView.isHidden = true
                self?.mapy_disConnectAnimeView.stop()
                self?.mapy_connectAnimeView.isHidden = true
                self?.mapy_connectAnimeView.stop()
                //                self?.mapy_ipView.isHidden = true
                //                self?.mapy_speedView.isHidden = true
                self?.mapy_titleLabel.text = "NO CONNECT"
                
                
            }
        }
        MAPYManager.mapy_manager.mapy_configVpnAuth {[weak self] _, _ in
            if MAPYManager.mapy_manager.mapy_vpnCurStateType == .mapy_connected {
                self?.mapy_connectButton.isSelected = true
                self?.mapy_ipView.isHidden = false
                self?.mapy_speedView.isHidden = false
                self?.mapy_titleLabel.text = "CONNECTED"
            }
        }
       
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    //MARK: - mapy action
    func mapy_addAnmate() {
        mapy_connectButton.layer.removeAllAnimations()
        if MAPYManager.mapy_manager.mapy_vpnCurStateType == .mapy_invalid ||  MAPYManager.mapy_manager.mapy_vpnCurStateType == .mapy_disconnected  {
            mapy_connectButton.layer.add(mapy_loadingKey, forKey: "mapy_loadingKey")
        }
        
    }
    func mapy_reloadIpShow() {
        if MAPYManager.mapy_manager.mapy_vpnCurStateType == .mapy_connected {
            mapy_iPValueLabel.text = MAPYManager.mapy_manager.mapy_curServerModel?.mapy_address
            mapy_timeView.isHidden = true
            mapy_downloadLabel.isHidden = false
            mapy_downloadValueLabel.isHidden = false
            mapy_uploadLabel.isHidden = false
            mapy_uploadValueLabel.isHidden = false
            mapy_downUnitLabel.isHidden = false
            mapy_upUnitLabel.isHidden = false
        }else {
            mapy_iPValueLabel.text = ""
            mapy_timeView.isHidden = false
            mapy_downloadLabel.isHidden = true
            mapy_downloadValueLabel.isHidden = true
            mapy_uploadLabel.isHidden = true
            mapy_uploadValueLabel.isHidden = true
            mapy_downUnitLabel.isHidden = true
            mapy_upUnitLabel.isHidden = true
        }
        mapy_addAnmate()
    }
    @objc func mapy_connectClick() {
        MAPYManager.mapy_manager.mapy_smart = false
        MAPYManager.mapy_manager.mapy_best = false
        if MAPYManager.mapy_manager.mapy_vpnCurStateType == .mapy_connected {
            MAPYManager.mapy_manager.mapy_stopConnect()
            MAPYManager.mapy_manager.mapy_vpnStateClickType = .mapy_disConnect
            
        }else {
            MAPYManager.mapy_manager.mapy_vpnStateClickType = .mapy_connect
            MAPYManager.mapy_manager.mapy_connectSelectAddreddAction()
        }
    }
    @objc func mapy_changeServersClick() {
        mapy_viewGetVController?.navigationController?.pushViewController(MAPYServersListViewController(), animated: true)
    }
    @objc func mapy_testClick(mapy_view: UITapGestureRecognizer) {
        if MAPYManager.mapy_manager.mapy_netType == .mapy_none {
            MAPYHudCommon.mapy_showMessage("No available network", isError: false)
            return
        }
        if mapy_view.view == mapy_ipView {
            mapy_viewGetVController?.navigationController?.pushViewController(MAPYScanViewController(mapy_funcType: .mapy_ip), animated: true)
            return
        }
        if mapy_view.view == mapy_speedView {
            mapy_viewGetVController?.navigationController?.pushViewController(MAPYScanViewController(mapy_funcType: .mapy_speed), animated: true)
        }
    }
    func mapy_reloadSpeedValue() {
        if MAPYManager.mapy_manager.mapy_vpnCurStateType == .mapy_connected {
            let mapy_down = MAPYCommon.mapy_getSizeValue(size: MAPYManager.mapy_manager.mapy_homeDownloadValue)
            let mapy_up = MAPYCommon.mapy_getSizeValue(size: MAPYManager.mapy_manager.mapy_homeUploadValue)
            mapy_downloadValueLabel.text = mapy_down.0
            mapy_upUnitLabel.text = mapy_down.1
            mapy_uploadValueLabel.text = mapy_up.0
            mapy_downUnitLabel.text = mapy_up.1
        }else {
            mapy_downloadValueLabel.text = "-"
            mapy_uploadValueLabel.text = "-"
            mapy_upUnitLabel.text = "MB/s"
            mapy_downUnitLabel.text = "MB/s"
        }
    }
    //MARK: - mapy lazy
    lazy var mapy_loadingKey: CABasicAnimation = {
        let mapy_loadingKey = CABasicAnimation.init(keyPath: "transform.scale")
        mapy_loadingKey.fromValue = 1.0 // 初始缩放比例
        mapy_loadingKey.toValue = 1.1   // 最终缩放比例
        mapy_loadingKey.duration = 0.5   // 动画持续时间（秒）
        mapy_loadingKey.autoreverses = true // 自动返回到初始状态
        mapy_loadingKey.repeatCount = MAXFLOAT
        return mapy_loadingKey
    }()
    lazy var mapy_iPValueLabel: UILabel = {
        let mapy_valueLabel = UILabel()
        mapy_valueLabel.font = UIFont.systemFont(ofSize: 12)
        mapy_valueLabel.textColor = MAPYCommon.mapy_getHXColorValue(rgb: 0xFFFFFF, a: 0.45)
        mapy_valueLabel.text = ""
        return mapy_valueLabel
    }()
    lazy var mapy_ipView: MAPYHomeTestItemView = {
        let mapy_ipView = MAPYHomeTestItemView()
//        mapy_ipView.isHidden = true
        mapy_ipView.mapy_addTap(target: self,action: #selector(mapy_testClick(mapy_view:)))
        return mapy_ipView
    }()
    lazy var mapy_speedView: MAPYHomeTestItemView = {
        let mapy_speedView = MAPYHomeTestItemView()
        mapy_speedView.mapy_iconView.image = UIImage(named: "mapy_home_speed")
        mapy_speedView.mapy_titleLabel.text = "NET test"
//        mapy_speedView.isHidden = true
        mapy_speedView.mapy_addTap(target: self,action: #selector(mapy_testClick(mapy_view:)))
        return mapy_speedView
    }()
    lazy var mapy_bottomView: UIImageView = {
        let mapy_bottomView = UIImageView(image: UIImage(named: "mapy_home_connectbg"))
        return mapy_bottomView
    }()
    lazy var mapy_connectButton: UIButton = {
        let mapy_connectButton = UIButton()
        mapy_connectButton.setBackgroundImage(UIImage(named: "mapy_home_connect"), for: .normal)
        mapy_connectButton.setBackgroundImage(UIImage(named: "mapy_home_disConnect"), for: .selected)
        mapy_connectButton.addTarget(self, action: #selector(mapy_connectClick), for: .touchUpInside)
        return mapy_connectButton
    }()
    lazy var mapy_connectAnimeView: LottieAnimationView = {
        let mapy_connectAnimeView = LottieAnimationView(name: "mapy_startConnect")
        mapy_connectAnimeView.loopMode = .loop
        mapy_connectAnimeView.backgroundBehavior = .pauseAndRestore
        mapy_connectAnimeView.animationSpeed = 1
        mapy_connectAnimeView.contentMode = .scaleAspectFit
//        mapy_connectAnimeView.play()
        mapy_connectAnimeView.isHidden = true
        return mapy_connectAnimeView
    }()
    lazy var mapy_disConnectAnimeView: LottieAnimationView = {
        let mapy_disConnectAnimeView = LottieAnimationView(name: "mapy_stopConnect")
        mapy_disConnectAnimeView.loopMode = .loop
        mapy_disConnectAnimeView.backgroundBehavior = .pauseAndRestore
        mapy_disConnectAnimeView.animationSpeed = 1
        mapy_disConnectAnimeView.contentMode = .scaleAspectFit
//        mapy_disConnectAnimeView.play()
        mapy_disConnectAnimeView.isHidden = true
        return mapy_disConnectAnimeView
    }()
    lazy var mapy_titleLabel: UILabel = {
        let mapy_titleLabel = UILabel()
        mapy_titleLabel.font = UIFont.systemFont(ofSize: 24)
        mapy_titleLabel.textColor = MAPYCommon.mapy_getHXColorValue(rgb: 0xFFFFFF)
        mapy_titleLabel.text = "NO CONNECT"
        return mapy_titleLabel
    }()
    lazy var mapy_downloadLabel: UILabel = {
        let mapy_downloadLabel = UILabel()
        mapy_downloadLabel.font = UIFont.systemFont(ofSize: 14)
        mapy_downloadLabel.textColor = MAPYCommon.mapy_getHXColorValue(rgb: 0xFFFFFF, a: 0.45)
        mapy_downloadLabel.text = "DOWNLOAD"
        return mapy_downloadLabel
    }()
    lazy var mapy_downloadValueLabel: UILabel = {
        let mapy_valueLabel = UILabel()
        mapy_valueLabel.font = UIFont.systemFont(ofSize: 20)
        mapy_valueLabel.textColor = MAPYCommon.mapy_getHXColorValue(rgb: 0xFFFFFF)
        mapy_valueLabel.text = "-"
        return mapy_valueLabel
    }()
    lazy var mapy_downUnitLabel: UILabel = {
        let mapy_downUnitLabel = UILabel()
        mapy_downUnitLabel.font = UIFont.systemFont(ofSize: 12)
        mapy_downUnitLabel.textColor = MAPYCommon.mapy_getHXColorValue(rgb: 0xFFFFFF, a: 0.22)
        mapy_downUnitLabel.text = "MB/s"
        return mapy_downUnitLabel
    }()
    lazy var mapy_uploadLabel: UILabel = {
        let mapy_uploadLabel = UILabel()
        mapy_uploadLabel.font = UIFont.systemFont(ofSize: 14)
        mapy_uploadLabel.textColor = MAPYCommon.mapy_getHXColorValue(rgb: 0xFFFFFF, a: 0.45)
        mapy_uploadLabel.text = "UPLOAD"
        return mapy_uploadLabel
    }()
    lazy var mapy_uploadValueLabel: UILabel = {
        let mapy_uploadValueLabel = UILabel()
        mapy_uploadValueLabel.font = UIFont.systemFont(ofSize: 20)
        mapy_uploadValueLabel.textColor = MAPYCommon.mapy_getHXColorValue(rgb: 0xFFFFFF)
        mapy_uploadValueLabel.text = "-"
        return mapy_uploadValueLabel
    }()
    lazy var mapy_upUnitLabel: UILabel = {
        let mapy_upUnitLabel = UILabel()
        mapy_upUnitLabel.font = UIFont.systemFont(ofSize: 12)
        mapy_upUnitLabel.textColor = MAPYCommon.mapy_getHXColorValue(rgb: 0xFFFFFF, a: 0.22)
        mapy_upUnitLabel.text = "MB/s"
        return mapy_upUnitLabel
    }()
    lazy var mapy_changeView: MAPYHomeChangeServerView = {
        let mapy_changeView = MAPYHomeChangeServerView()
        mapy_changeView.mapy_addTap(target: self, action: #selector(mapy_changeServersClick))
        return mapy_changeView
    }()
    lazy var mapy_selectView: MAPYHomeSelectView = {
        let mapy_selectView = MAPYHomeSelectView()
        mapy_selectView.mapy_homeSelectBock = {[weak self] in
            self?.mapy_connectAnimeView.isHidden = false
            self?.mapy_connectAnimeView.play()
            MAPYManager.mapy_manager.mapy_vpnStateClickType = .mapy_disConnect
            MAPYManager.mapy_manager.mapy_connectSmartAction()
        }
        return mapy_selectView
    }()
    lazy var mapy_timeView: MAPYHomeTimeView = {
        let mapy_timeView = MAPYHomeTimeView()
        return mapy_timeView
    }()
}

class MAPYHomeChangeServerView: UIView {
    override init(frame: CGRect) {
        super.init(frame: frame)
        addSubview(mapy_bottomView)
        addSubview(mapy_iconView)
        addSubview(mapy_titleLabel)
        addSubview(mapy_arrowView)
        mapy_bottomView.snp.makeConstraints { make in
            make.edges.equalToSuperview()
        }
        mapy_iconView.snp.makeConstraints { make in
            make.top.equalToSuperview().offset(18)
            make.left.equalToSuperview().offset(20)
            make.size.equalTo(CGSize(width: 56, height: 32))
        }
        mapy_titleLabel.snp.makeConstraints { make in
            make.centerY.equalTo(mapy_iconView.snp.centerY)
            make.left.equalTo(mapy_iconView.snp.right).offset(12)
        }
        mapy_arrowView.snp.makeConstraints { make in
            make.size.equalTo(18)
            make.centerY.equalTo(mapy_iconView.snp.centerY)
            make.right.equalToSuperview().offset(-24)
        }
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    lazy var mapy_bottomView: UIImageView = {
        let mapy_bottomView = UIImageView(image: UIImage(named: "mapy_home_change"))
        return mapy_bottomView
    }()
    lazy var mapy_iconView: UIImageView = {
        let mapy_iconView = UIImageView(image: UIImage(named: "mapy_home_changeIcon"))
        return mapy_iconView
    }()
    lazy var mapy_titleLabel: UILabel = {
        let mapy_titleLabel = UILabel()
        mapy_titleLabel.font = UIFont.systemFont(ofSize: 12)
        mapy_titleLabel.textColor = MAPYCommon.mapy_getHXColorValue(rgb: 0xFFFFFF)
        mapy_titleLabel.text = "Change severs"
        return mapy_titleLabel
    }()
    lazy var mapy_arrowView: UIImageView = {
        let mapy_arrowView = UIImageView(image: UIImage(named: "mapy_home_changeArrow"))
        return mapy_arrowView
    }()
}

class MAPYHomeSelectView: UIView {
    override init(frame: CGRect) {
        super.init(frame: frame)
        addSubview(mapy_bottomView)
        addSubview(mapy_bestView)
        addSubview(mapy_smartView)
        mapy_bottomView.snp.makeConstraints { make in
            make.edges.equalToSuperview()
        }
        mapy_bestView.snp.makeConstraints { make in
            make.left.bottom.height.equalToSuperview()
            make.right.equalTo(self.snp.centerX)
        }
        mapy_smartView.snp.makeConstraints { make in
            make.right.bottom.height.equalToSuperview()
            make.left.equalTo(self.snp.centerX)
        }
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    @objc func mapy_serverConnectClick(mapy_tap: UITapGestureRecognizer) {
        if mapy_tap.view == mapy_bestView {
            MAPYManager.mapy_manager.mapy_smart = false
            MAPYManager.mapy_manager.mapy_best = true
            
        }else
        if mapy_tap.view == mapy_smartView {
            MAPYManager.mapy_manager.mapy_best = false
            MAPYManager.mapy_manager.mapy_smart = true
        }
        mapy_homeSelectBock?()
    }
    var mapy_homeSelectBock:(()->())?
    lazy var mapy_bottomView: UIImageView = {
        let mapy_bottomView = UIImageView(image: UIImage(named: "mapy_home_selectbg"))
        return mapy_bottomView
    }()
    lazy var mapy_bestView: MAPYHomeSelectItemView = {
        let mapy_bestView = MAPYHomeSelectItemView()
        mapy_bestView.mapy_addTap(target: self, action: #selector(mapy_serverConnectClick(mapy_tap:)))
        return mapy_bestView
    }()
    lazy var mapy_smartView: MAPYHomeSelectItemView = {
        let mapy_smartView = MAPYHomeSelectItemView()
        mapy_smartView.mapy_titleLabel.text = "Stable servers"
        mapy_smartView.mapy_addTap(target: self, action: #selector(mapy_serverConnectClick(mapy_tap:)))
        return mapy_smartView
    }()
}

class MAPYHomeSelectItemView: UIView {
    override init(frame: CGRect) {
        super.init(frame: frame)
        addSubview(mapy_titleLabel)
        addSubview(mapy_arrowView)
        mapy_titleLabel.snp.makeConstraints { make in
            make.centerY.equalToSuperview()
            make.left.equalToSuperview().offset(16)
        }
        mapy_arrowView.snp.makeConstraints { make in
            make.centerY.equalToSuperview()
            make.right.equalToSuperview().offset(-10)
        }
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    lazy var mapy_titleLabel: UILabel = {
        let mapy_titleLabel = UILabel()
        mapy_titleLabel.font = UIFont.systemFont(ofSize: 12)
        mapy_titleLabel.textColor = MAPYCommon.mapy_getHXColorValue(rgb: 0xFFFFFF)
        mapy_titleLabel.text = "Best severs"
        return mapy_titleLabel
    }()
    lazy var mapy_arrowView: UIImageView = {
        let mapy_arrowView = UIImageView(image: UIImage(named: "mapy_home_selectArrow"))
        return mapy_arrowView
    }()
}

class MAPYHomeTestItemView: UIView {
    override init(frame: CGRect) {
        super.init(frame: frame)
        addSubview(mapy_bgView)
        addSubview(mapy_titleLabel)
        addSubview(mapy_iconView)
        mapy_bgView.snp.makeConstraints { make in
            make.edges.equalToSuperview()
        }
        mapy_titleLabel.snp.makeConstraints { make in
            make.centerX.equalToSuperview()
            make.top.equalTo(mapy_iconView.snp.bottom).offset(4)
        }
        mapy_iconView.snp.makeConstraints { make in
            make.size.equalTo(24)
            make.centerX.equalToSuperview()
            make.top.equalToSuperview().offset(30)
        }
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    lazy var mapy_bgView: UIImageView = {
        let mapy_bgView = UIImageView(image: UIImage(named: "mapy_home_testBg"))
        return mapy_bgView
    }()
    lazy var mapy_titleLabel: UILabel = {
        let mapy_titleLabel = UILabel()
        mapy_titleLabel.font = UIFont.systemFont(ofSize: 12)
        mapy_titleLabel.textColor = MAPYCommon.mapy_getHXColorValue(rgb: 0xFFFFFF)
        mapy_titleLabel.text = "IP info"
        return mapy_titleLabel
    }()
    lazy var mapy_iconView: UIImageView = {
        let mapy_iconView = UIImageView(image: UIImage(named: "mapy_home_ip"))
        return mapy_iconView
    }()
}


class MAPYHomeTimeView: UIView {
    override init(frame: CGRect) {
        super.init(frame: frame)
        addSubview(mapy_titleLabel)
        addSubview(mapy_timeLabel)
        mapy_titleLabel.snp.makeConstraints { make in
            make.top.equalToSuperview().offset(55)
            make.centerX.equalToSuperview()
        }
        mapy_timeLabel.snp.makeConstraints { make in
            make.top.equalTo(mapy_titleLabel.snp.bottom).offset(16)
            make.centerX.equalToSuperview()
        }
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    lazy var mapy_titleLabel: UILabel = {
        let mapy_titleLabel = UILabel()
        mapy_titleLabel.font = UIFont.systemFont(ofSize: 14)
        mapy_titleLabel.textColor = MAPYCommon.mapy_getHXColorValue(rgb: 0xFFFFFF, a: 0.45)
        mapy_titleLabel.text = "TO CONNECT"
        return mapy_titleLabel
    }()
    lazy var mapy_timeLabel: UILabel = {
        let mapy_timeLabel = UILabel()
        mapy_timeLabel.font = UIFont.systemFont(ofSize: 24)
        mapy_timeLabel.textColor = MAPYCommon.mapy_getHXColorValue(rgb: 0xFFFFFF)
        mapy_timeLabel.text = "00:00:00"
        return mapy_timeLabel
    }()
}
